//
//  MoreViewController.m
//  babyMemoryPro
//
//  Created by student on 15-6-30.
//  Copyright (c) 2015年 niit. All rights reserved.
//

#import "MoreViewController.h"
#import "MoreCell.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDK/ISSContent.h>
#import "SetMailViewController.h"
#import "AppDelegate.h"
@interface MoreViewController (){
    NSArray *imgArr;
}

@end

@implementation MoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.moreList=@[@"版本信息",@"关于我们",@"分享",@"留言"];
    imgArr=@[@"image0.jpg",@"image1.jpg",@"image2.jpg",@"image3.jpg"];
    [self.tableView registerNib:[UINib nibWithNibName:@"MoreCell" bundle:nil] forCellReuseIdentifier:@"MoreCell"];
    self.tableView.separatorStyle=UITableViewCellAccessoryNone;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.moreList.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier=@"MoreCell";
    MoreCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    cell.labelField.text=[NSString stringWithFormat: @"%@",self.moreList[indexPath.row]];
    cell.imageView.image=[UIImage imageNamed:imgArr[indexPath.row]];
//    NSLog(@"%@",imgArr[indexPath.row]);
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0) {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"版本信息" message:@"当前版本：1.0.0" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
    else     if (indexPath.row==1) {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"关于我们" message:@"由于目前大部分家庭都是独生子女，家里的孩子是双方家庭的宝贝，每个家庭成员都时刻关注着它的成长。所以我们为拥有孩子的家庭提供了一个可以记录孩子成长的平台。" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
    else if (indexPath.row==2){
        [self shareToWeiXin];
    }
    else if (indexPath.row==3){
        AppDelegate *app = [UIApplication sharedApplication].delegate;
        SetMailViewController *setMailVC=[[SetMailViewController alloc]init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:setMailVC];
        app.slider.rootViewController = nav;
        
        

    }
}




- (void)shareToWeiXin
{
    
    id<ISSContainer> container = [ShareSDK container];
    [container setIPhoneContainerWithViewController:self];
    
    NSArray *shareList = [ShareSDK getShareListWithType:
                          ShareTypeWeixiSession,
                          nil];
    
    //NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"ShareSDK"  ofType:@"jpg"];
    
    //构造分享内容
    id<ISSContent> publishContent = [ShareSDK content:@"快来围观我家宝宝的成长经历吧！！！"
                                       defaultContent:@"默认分享内容，没内容时显示"
                                                image:nil
                                                title:@"宝宝成长录"
                                                  url:@"http://store.apple.com/cn"
                                          description:nil
                                            mediaType:SSPublishContentMediaTypeNews];
    
    
    id<ISSShareOptions> shareOptions =
    [ShareSDK defaultShareOptionsWithTitle:@""
                           oneKeyShareList:shareList
                        cameraButtonHidden:YES
                       mentionButtonHidden:NO
                         topicButtonHidden:NO
                            qqButtonHidden:YES
                     wxSessionButtonHidden:YES
                    wxTimelineButtonHidden:YES
                      showKeyboardOnAppear:NO
                         shareViewDelegate:nil
                       friendsViewDelegate:nil
                     picViewerViewDelegate:nil];
    
    
    [ShareSDK showShareActionSheet:container
                         shareList:shareList
                           content:publishContent
                     statusBarTips:YES
                       authOptions:nil
                      shareOptions:shareOptions
                            result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
                                
                                NSString *name = nil;
                                switch (type)
                                {
                                    case ShareTypeWeixiSession:
                                        name = @"微信朋友圈";
                                        break;
                                    default:
                                        name = @"某个平台";
                                        break;
                                }
                                
                                NSString *notice = nil;
                                if (state == SSResponseStateSuccess)
                                {
                                    notice = [NSString stringWithFormat:@"分享到%@成功！", name];
                                    NSLog(@"%@",notice);
                                    UIAlertView *view =
                                    [[UIAlertView alloc] initWithTitle:@"提示"
                                                               message:notice
                                                              delegate:nil
                                                     cancelButtonTitle:@"知道了"
                                                     otherButtonTitles: nil];
                                    [view show];
                                    
                                }
                                else if (state == SSResponseStateFail)
                                {
                                    notice = [NSString stringWithFormat:@"分享失败,错误码:%d,错误描述:%@", [error errorCode], [error errorDescription]];
                                    NSLog(@"%@",notice);
                                    
                                    UIAlertView *view =
                                    [[UIAlertView alloc] initWithTitle:@"提示"
                                                               message:notice
                                                              delegate:nil
                                                     cancelButtonTitle:@"知道了"
                                                     otherButtonTitles: nil];
                                    [view show];
                                    
                                }
                            }];
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}


// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Table view delegate

// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here, for example:
    // Create the next view controller.
    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:<#@"Nib name"#> bundle:nil];
    
    // Pass the selected object to the new view controller.
    
    // Push the view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
